# 对比器：将内网包信息和外网包信息进行比对。得出更新建议
from UpdatePlat.LocalPackList import LocalPackList
from UpdatePlat.OnlinePackList import OnlinePackList
import copy


def compare(url):
    # 包对比
    localpacks = LocalPackList(url).packlist
    onlinepacks = OnlinePackList(url).packlist
    localpackleave = copy.deepcopy(localpacks)
    onlinepackleave = copy.deepcopy(onlinepacks)
    for mumber in onlinepacks:
        if mumber in localpacks:
            localpackleave.remove(mumber)
            onlinepackleave.remove(mumber)
    # 生成结论
    result = []
    re_count = "需要从外网源下载：{}个包，需要从内网源删除：{}个包".format(len(onlinepackleave), len(localpackleave))
    result.append(re_count)
    for packname in localpackleave:
        re_pack = "- {}".format(packname)
        result.append(re_pack)
    for packname in onlinepackleave:
        re_pack = "+ {}".format(packname)
        result.append(re_pack)
    return result

